#!/bin/bash

# 设置颜色输出
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

# 打印带颜色的消息
print_info() {
    echo -e "${BLUE}[信息]${NC} $1"
}

print_success() {
    echo -e "${GREEN}[成功]${NC} $1"
}

print_warning() {
    echo -e "${YELLOW}[警告]${NC} $1"
}

print_error() {
    echo -e "${RED}[错误]${NC} $1"
}

echo
echo "==============================================================================="
echo "                        MCP代码生成系统 v2.0"
echo "                         环境安装脚本 (Linux)"
echo "==============================================================================="
echo

# 检查uv是否已安装
print_info "检查uv包管理器..."
if ! command -v uv &> /dev/null; then
    print_error "uv未安装，请先安装uv包管理器"
    print_info "安装命令: curl -LsSf https://astral.sh/uv/install.sh | sh"
    exit 1
fi

UV_VERSION=$(uv --version)
print_success "uv已安装: $UV_VERSION"

# 初始化workspace环境
echo
print_info "正在初始化workspace环境..."
if uv sync --all-packages; then
    print_success "workspace环境初始化成功"
else
    print_error "workspace环境初始化失败"
    exit 1
fi

# 检查API密钥配置
echo
print_info "检查API密钥配置..."
if [ -z "$DASHSCOPE_API_KEY" ]; then
    print_warning "未设置DASHSCOPE_API_KEY环境变量"
    print_info "请设置: export DASHSCOPE_API_KEY=your_key_here"
fi

# 创建日志目录
mkdir -p logs

# 设置脚本执行权限
chmod +x scripts/*.sh

echo
print_success "环境安装完成！"
echo
print_info "下一步: 启动系统: ./scripts/start.sh"
echo
